from flask import session, redirect, url_for, render_template, jsonify, request

from web import APP

@APP.route('/system/index')
def html_system_index():
    '''框架页面'''
    return render_template('index.html')

@APP.route('/system/cache/clear')
def html_cache_clear():
    return jsonify({'code': 1, 'msg': '服务端缓存清理成功'})

@APP.route('/system/dashboard')
def html_dashboard():
    '''仪表盘'''
    return render_template('system/dashboard.html')

@APP.route('/system/install_packages')
def html_install_packages():
    '''安装包'''
    return render_template('system/install_packages.html')

@APP.route('/system/server')
def html_server():
    '''服务'''
    return render_template('system/server.html')

@APP.route('/system/usermanager')
def html_usermanager():
    '''用户管理'''
    return render_template('system/user_manager.html')

@APP.route('/system/menu/init')
def html_menu_init():
    '''菜单'''
    home_menu = {'title': '主页', 'icon': 'fa fa-home', 'href': ''}
    logo_menu = {'title': 'WatchDog', 'image': url_for('static', filename='res/watchdog.ico'), 'href':''}
    system_menu = {'title': '系统管理', 'icon': 'fa fa-gears', 'child': [
        {'title': '仪表盘', 'href': url_for('html_dashboard'), 'icon': 'fa fa-users', 'target': '_self'},
        {'title': '安装包', 'href': url_for('html_install_packages'), 'icon': 'fa fa-users', 'target': '_self'},
        {'title': '服务', 'href': url_for('html_server'), 'icon': 'fa fa-users', 'target': '_self'},
        {'title': '用户管理', 'href': url_for('html_usermanager'), 'icon': 'fa fa-users', 'target': '_self'}
    ] }
    menu_dict = {'homeInfo': home_menu, 'logoInfo': logo_menu, 'menuInfo': [system_menu]}
    return jsonify(menu_dict)